package net.hmr_radio.hmrbot.controller.bot;

import net.hmr_radio.hmrbot.controller.BaseLoggedInController;
import net.hmr_radio.hmrbot.service.BotService;

import org.slim3.controller.Navigation;
import org.slim3.controller.validator.RequiredValidator;
import org.slim3.controller.validator.Validators;

import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

public class DeleteController extends BaseLoggedInController {

    private BotService botService = new BotService();

    private UserService userService = UserServiceFactory.getUserService();

    @Override
    public Navigation doRun() throws Exception {
        Validators v = new Validators(request);
        v.add("key", RequiredValidator.INSTANCE);
        if (!v.validate()) {
            throw new IllegalArgumentException("パラメータが不正");
        }

        botService.delete(asKey("key"), userService
            .getCurrentUser()
            .getUserId());

        return redirect("/mypage/");
    }
}
